package com.example.constellation.utils;

import android.app.ProgressDialog;
import android.content.Context;
import android.os.AsyncTask;

public class LoadData extends AsyncTask<String,Void,String> {
    private Context context;
    private ongetnetdata ongetnetdata1;
    private ProgressDialog dialog;
    private boolean isshowlog=false;

    private void initdialog(){
        dialog=new ProgressDialog(context);
        dialog.setTitle("提示信息");
        dialog.setMessage("正在加载...");
    }

    public LoadData(Context context, LoadData.ongetnetdata ongetnetdata1,boolean isshowlog) {
        this.context = context;
        this.ongetnetdata1 = ongetnetdata1;
        this.isshowlog=isshowlog;
        initdialog();
    }

    public interface ongetnetdata{
        public void onsucess(String json);
    }
    @Override
    //在子线程中，进行耗时操作等逻辑（网络请求）
    protected String doInBackground(String... params) {
        String getjson = HttpUtils.getjson(params[0]);
        return getjson;
    }

    //运行在主线程中,进行控件初始化
    @Override
    protected void onPreExecute() {
        super.onPreExecute();
        if (isshowlog) {
            dialog.show();
        }

    }

    //在主线程中 得到doinbackground返回的数据 进行控件的更新
    @Override
    protected void onPostExecute(String s) {
        super.onPostExecute(s);
        if (isshowlog) {
            dialog.dismiss();
        }
        ongetnetdata1.onsucess(s);
    }
}
